Automatic transformation of iterative loops into recursive methods
نویسندگان
چکیده
Context: In software engineering, taking a good election between recursion and iteration is essential because their efficiency and maintenance are different. In fact, developers often need to transform iteration into recursion (e.g., in debugging, to decompose the call graph into iterations); thus, it is quite surprising that there does not exist a public transformation from loops to recursion that can be used in industrial projects (i.e., it is automatic, it handles all kinds of loops, it considers exceptions, etc.). Objective: This article describes an industrial algorithm implemented as a Java library able to automatically transform iterative loops into equivalent recursive methods. The transformation is described for the programming language Java, but it is general enough as to be adapted to many other languages that allow iteration and recursion. Method: We describe the changes needed to transform loops of types while/do/for/foreach into recursion. We provide a transformation schema for each kind of loop. Results: Our algorithm is the first public transformation that can be used in industrial projects and faces the whole Java language (i.e., it is fully automatic, it handles all kinds of loops, it considers exceptions, it treats the control statements break and continue, it handles loop labels, it is able to transform any number of nested loops, etc.). This is particularly interesting because some of these features are missing in all previous work, probably, due to the complexity that their mixture introduce in the transformation. Conclusion: Developers should use a methodology when transforming code, specifically when transforming loops into recursion. This article provides guidelines and algorithms that allow them to face different problems such as exception handling. The implementation has been made publicly available as open source.
منابع مشابه
Transforming while/do/for/foreach-Loops into Recursive Methods
In software engineering, taking a good election between recursion and iteration is essential because their efficiency and maintenance are different. In fact, developers often need to transform iteration into recursion (e.g., in debugging, to decompose the call graph into iterations); thus, it is quite surprising that there does not exist a public transformation from loops to recursion that hand...
متن کاملAutomatic program synthesis via synthesis
Work on theorem-proving-based automatic program synthesis (see Lee, e t ai.,1 for example) has been neglected iately. In their 1971 paper, Manna and Waldinger8 covered one of the main reasons why-the difficulty of synthesizing program loops within the current state of the art of automatic theorem-proving.· However, there is a great deal of continuing work in theorem-proving, and it is important...
متن کاملتحلیل قابلیت اعتماد فازی سازهها با استفاده از روش دینامیکی انتقال پایدار امتدادی
In this paper, a new method is proposed for fuzzy structural reliability analysis; it considers epistemic uncertainty arising from the statistical ambiguity of random variables. The proposed method, namely, fuzzy dynamic-directional stability transformation method, includes two iterative loops. An internal algorithm performs the reliability analysis using the dynamic-directional stability trans...
متن کاملA Purely Logical Approach to Program Termination
We present our work in progress concerning the logical foundations of the analysis of termination for imperative recursive programs. The analysis is based on forward symbolic execution [12] and functional semantics. The distinctive feature of our approach is the formulation of the termination condition as an induction principle developed from the structure of the program with respect to iterati...
متن کاملAchieving Full Parallelism Using Multidimensional Retiming
Most scientiic and Digital Signal Processing (DSP) applications are recursive or iterative. Transformation techniques are usually applied to get optimal execution rates in parallel and/or pipeline systems. The retiming technique is a common and valuable transformation tool in one-dimensional problems, when loops are represented by data ow graphs (DFGs). In this paper, uniform nested loops are m...
متن کاملذخیره در منابع من
با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید
عنوان ژورنال:
- Information & Software Technology
دوره 58 شماره
صفحات -
تاریخ انتشار 2015